package dhbw.GUI.Panels;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import Main.MyController;
import dhbw.Data.Language;
import dhbw.Data.Settings;

public class ContentPanelRoleSelection extends JPanel implements ActionListener{
	
	protected JRadioButton radioStudent, radioDozent,radioProfessor;
	protected ButtonGroup radioGroup;
	protected JComboBox cb_Kurs;
	protected JTextField tf_kurs;
	private JLabel l_kurs,l_kurs2;
	private MyController myc;
	
	public ContentPanelRoleSelection(MyController myc)
	{
		this.myc = myc;
		build();
	}
	
	public void build()
	{
		this.setBackground(Settings.BG_COLOR);
		CellConstraints cc = new CellConstraints();
		String cols = "16dlu,40dlu,6dlu,80dlu,16dlu";
		String rows = "6dlu,pref,12dlu,pref,12dlu,pref,6dlu";
		FormLayout grid = new FormLayout(cols, rows);
		
		this.setLayout(grid);
		JPanel radioPanel = new JPanel();
		radioPanel.setLayout(new GridLayout(3, 1));
		
		cb_Kurs = new JComboBox();
		radioGroup = new ButtonGroup();
		radioDozent = new JRadioButton(Language.LECTURER[myc.getLanguage()]);
		radioProfessor = new JRadioButton(Language.PROFESSOR[myc.getLanguage()]);
		radioStudent = new JRadioButton(Language.STUDENT[myc.getLanguage()]);
		
		radioDozent.setBackground(Settings.BG_COLOR);
		radioProfessor.setBackground(Settings.BG_COLOR);
		radioStudent.setBackground(Settings.BG_COLOR);
		radioPanel.setBackground(Settings.BG_COLOR);
		
		radioGroup.add(radioStudent);
		radioGroup.add(radioDozent);
		radioGroup.add(radioProfessor);
		
		radioDozent.addActionListener(this);
		radioProfessor.addActionListener(this);
		radioStudent.addActionListener(this);
		
		radioPanel.add(radioStudent);
		radioPanel.add(radioDozent);
		radioPanel.add(radioProfessor);
		
		radioStudent.setSelected(true);
		tf_kurs = new JTextField();
		l_kurs = new JLabel(Language.CLASS[myc.getLanguage()]);
		l_kurs2 = new JLabel(Language.CLASS[myc.getLanguage()]+" ("+Language.NEW[this.myc.getLanguage()]+")");
		this.add(new JLabel(Language.ROLE[myc.getLanguage()]),cc.xy(2, 2));
		this.add(radioPanel,cc.xy(4, 2));
		this.add(l_kurs,cc.xy(2, 4));
		
		this.add(cb_Kurs,cc.xy(4, 4));
		this.add(l_kurs2,cc.xy(2, 6));
		this.add(tf_kurs,cc.xy(4, 6));
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource().equals(radioStudent))
		{
			cb_Kurs.setVisible(true);
			tf_kurs.setVisible(true);
			l_kurs.setVisible(true);
			l_kurs2.setVisible(true);
		}
		if(arg0.getSource().equals(radioProfessor) || arg0.getSource().equals(radioDozent))
		{
			cb_Kurs.setVisible(false);
			tf_kurs.setVisible(false);
			l_kurs.setVisible(false);
			l_kurs2.setVisible(false);
		}
	}
}
